package com.phjr.jicaimaoflutter;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.phjr.jicaimaoflutter.base.AdapterViewPager;
import com.phjr.jicaimaoflutter.base.ApiAdress;
import com.phjr.jicaimaoflutter.fragment.WebFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * description:
 * copyright  : Copyright (c) 20119
 * company    : 普华
 * date       : 2019/1/28 13:29
 * @author : austen
 */
public class ProductDetailActivity extends AppCompatActivity {
    private static final String TAG            = "ProductDetailActivity";
    public static final  String REWARD         = "REWARD";
    public static final  String REGULARPRODUCT = "REGULARPRODUCT";
    public static final  String WELFARE        = "WELFARE";
    @BindView(R.id.tabs_financial)
    TabLayout mTabFinancial;
    @BindView(R.id.vp_web)
    ViewPager mVpWbePage;
    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView  mTvTitle;
    @BindView(R.id.tv_buy)
    TextView  mTvBuy;
    @BindView(R.id.tv_reward)
    TextView mTvReWard;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_product_detail);
        ButterKnife.bind(this);


        Bundle outComingBundle = getIntent().getExtras();
        String reward = outComingBundle.getString(REWARD, "");
        String regularproduct = outComingBundle.getString(REGULARPRODUCT, "");
        String welfare = outComingBundle.getString(WELFARE, "");
        mTvTitle.setText(regularproduct + "天定期产品");
        mTvReWard.setText(reward);

        mIvBack.setOnClickListener(this::onViewed);
        mTvBuy.setOnClickListener(this::onViewed);

        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(WebFragment.newInstance(ApiAdress.BUY_RULES));
        fragments.add(WebFragment.newInstance(ApiAdress.EXTRACTION_RULES));
        fragments.add(WebFragment.newInstance(ApiAdress.COMMON_PROBLEM));
        String[] tabTitles = new String[]{
                "购买规则",
                "交易规则",
                "常见问题"
        };

        mTabFinancial.setupWithViewPager(mVpWbePage);
        AdapterViewPager adapterViewPager = new AdapterViewPager(getSupportFragmentManager(), fragments, tabTitles);
        mVpWbePage.setAdapter(adapterViewPager);
    }

    private void onViewed(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_buy:
                Toast.makeText(this, "申购", Toast.LENGTH_SHORT).show();

                break;
            default:
                break;
        }
    }


}
